<?php

class Drafts extends Model {
    var $name = 'Drafts';
    
    function get_user_drafts($page = 0, $user_id = null) {
        global $aldb;
        $perpage = 20;
        if (empty($user_id)) {
            $conditions = "FROM $aldb->post2category as c LEFT JOIN $aldb->posts as p ON c.post_id=p.id WHERE post_status='2' ";
        } else {
            $conditions = "FROM $aldb->post2category as c LEFT JOIN $aldb->posts as p ON c.post_id=p.id WHERE post_status='2' AND p.poster_id='$user_id'";
        }
        $posts->results = $aldb->get_results("SELECT p.id,p.post_title,p.poster_id,p.post_time,p.star_status,c.category_id  $conditions ");
        $count = $aldb->get_var("SELECT COUNT(c.id) $conditions");
        $total = ceil($count/$perpage);
        $posts->pagelink = get_pagelink(Router::get_url() . '/' . ARLICLE_ADMIN . '/drafts/drafts/', $page, $count, $perpage,$total);
        return $posts;
    }
}
?>
